package br.mestrado.unb.bs.util;

import br.mestrado.unb.bs.model.sensor.PayloadInterface;

public class CopyArrayUtil {

	public static void copyPayloadContent(byte[] pack, PayloadInterface payload,int indexInit) {
		byte []payloadStream = payload.toByteStream();
		int j = 0;
		for (int i = 0; i < payload.getSize(); i++) {
			pack[i + indexInit] = payloadStream[j++];
		}
	}
	
	/**
	 * Copy from i to j (including j) bytes from buffer array
	 * @param buffer
	 * @param i
	 * @param j
	 * @return
	 */
	public static byte[] copyOfRange(byte[] buffer, int i, int j) {
		if(j>=i){
			int x0=0;
			byte[] bs = new byte[(j+1-i)];
			for (int x1 = i; x1 < j+1; x1++) {
				bs[x0++] = buffer[x1]; 
			}
			return bs;
		}
		return null;
	}
}
